package track2.bayes;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import track2.context.Config;

public class IdFeatures implements Serializable {

	private static final long serialVersionUID = 3446517622835004107L;

	public static final double NOVALUE = -1;

	// store the probability of each feature;
	public double click;

	// titleid_tokensid.txt
	public double[] titleClick;
	public double[] titleNotClick;

	// queryid_tokensid.txt
	public double[] queryClick;
	public double[] queryNotClick;

	// descriptionid_tokensid.txt
	public double[] descriptionClick;
	public double[] descriptionNotClick;

	// purchasedkeywordid_tokensid.txt
	public double[] purchaseClick;
	public double[] purchaseNotClick;

	public double[] adClick;
	public double[] adNotClick;

	public double[] advertiserClick;
	public double[] advertiserNotClick;

	public double[] userClick;
	public double[] userNotClick;

	public IdFeatures() {
		
		titleClick = new double[Config.titleIdSize];
		titleNotClick = new double[Config.titleIdSize];
		queryClick = new double[Config.queryIdSize];
		queryNotClick = new double[Config.queryIdSize];
		descriptionClick = new double[Config.descriptionIdSize];
		descriptionNotClick = new double[Config.descriptionIdSize];
		purchaseClick = new double[Config.purchaseIdSize];
		purchaseNotClick = new double[Config.purchaseIdSize];
		adClick = new double[Config.adIdSize];
		adNotClick = new double[Config.adIdSize];
		advertiserClick = new double[Config.advertiserIdSize];
		advertiserNotClick = new double[Config.advertiserIdSize];
		userNotClick = new double[Config.userIdSize];
		userClick = new double[Config.userIdSize];

		click = 0.0;
		//initialize 
		for (int i = 0; i < Config.queryIdSize; i++) {
			queryClick[i] = NOVALUE;
			queryNotClick[i] = NOVALUE;
		}
		for (int i = 0; i < Config.titleIdSize; i++) {
			titleClick[i] = NOVALUE;
			titleNotClick[i] = NOVALUE;
		}
		for (int i = 0; i < Config.descriptionIdSize; i++) {
			descriptionClick[i] = NOVALUE;
			descriptionNotClick[i] = NOVALUE;
		}
		for (int i = 0; i < Config.purchaseIdSize; i++) {
			purchaseClick[i] = NOVALUE;
			purchaseNotClick[i] = NOVALUE;
		}
		for (int i = 0; i < Config.adIdSize; i++) {
			adClick[i] = NOVALUE;
			adNotClick[i] = NOVALUE;
		}
		for (int i = 0; i < Config.advertiserIdSize; i++) {
			advertiserClick[i] = NOVALUE;
			advertiserNotClick[i] = NOVALUE;
		}
		for (int i = 0; i < Config.userIdSize; i++) {
			userClick[i] = NOVALUE;
			userNotClick[i] = NOVALUE;
		}
		

	}

	public static void putObject(IdFeatures feature) {
		try {
			File file = new File(Config.idNaiveBayesFeaturePath);
			FileOutputStream fs = new FileOutputStream(file);
			ObjectOutputStream os = new ObjectOutputStream(fs);
			os.writeObject(feature);
			os.flush();
			os.close();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static IdFeatures getObject() {
		IdFeatures feature = null;
		try {
			File file = new File(Config.idNaiveBayesFeaturePath);
			FileInputStream fs = new FileInputStream(file);
			ObjectInputStream os = new ObjectInputStream(fs);
			feature = (IdFeatures) os.readObject();
			os.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return feature;

	}
}
